<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    账号: <input type="text" id="user"> <br>
    密码: <input type="text" id="psw"> <br>
    <input type="checkbox" id="remember"> 记住账号密码
    <button id="login">登录</button>
        
    <script src="./cookie.js"></script>
    <script>

       var res= getCookie("remember"); 
       console.log(res);//{"user":"34543","password":"543543"}


       if (res) {
        //有值
        var obj=JSON.parse(res);
        console.log(obj);
        user.value=obj.user
        psw.value=obj.password;
        remember.checked=true;
       }


        login.onclick=function(){
            if (!user.value) {
                alert("请输入账号")
                return
            }
            if (!psw.value) {
                alert("请输入密码")
                return
            }

            if (remember.checked) {
                // 已经勾选了记住账号密码
                // 存储
                // setCookie("user",user.value,7)
                setCookie("remember",JSON.stringify({user:user.value,password:psw.value}),7)
                
            } else {
                // 没有勾选  删除
                setCookie("remember","",-1)
            }



        }
        
    </script>
</body>
</html>